import 'package:flutter/material.dart';

class ChecBoxDemo extends StatefulWidget {
  ChecBoxDemo({Key key}) : super(key: key);
  @override
  _ChecBoxDemoState createState() => _ChecBoxDemoState();
}

class _ChecBoxDemoState extends State<ChecBoxDemo> {
  var flag = false;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('ChecBoxDemo'),
      ),
      body: Center(
          child: Column(
        children: [
          Checkbox(
              value: this.flag,
              onChanged: (value) {
                setState(() {
                  this.flag = value;
                });
              }),
          Text(this.flag ? '选中' : '未选中'),
          CheckboxListTile(
            value: this.flag,
            onChanged: (v) {
              setState(() {
                this.flag = v;
              });
            },
            title: Text('一级标题'),
            subtitle: Text('二级标题'),
            secondary: Icon(Icons.dangerous),
          )
        ],
      )),
    );
  }
}
